package com.mobile.check.activitys;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.ArrayList;

import cn.droidlover.xdroidmvp.base.BaseListActivity;
import cn.droidlover.xdroidmvp.base.BaseRecyclerAdapter;
import cn.droidlover.xdroidmvp.base.RecyclerViewHolder;

import com.mobile.check.beans.CheckItemInfo;
import com.mobile.check.beans.CheckItemResultInfo;

import com.mobile.check.app.R;
import com.mobile.check.present.BasePresent;

public class ScanResultDetailActivity extends BaseListActivity<CheckItemResultInfo, BasePresent> {
    long _id;
    @Override
    public BaseRecyclerAdapter<CheckItemResultInfo> getAdapter() {
        return new BaseRecyclerAdapter<CheckItemResultInfo>(this) {
            @Override
            public int getItemLayoutId(int viewType) {
                return R.layout.item_scanitemdetail;
            }

            @Override
            public void bindData(RecyclerViewHolder holder, int position) {
                super.bindData(holder, position);
                CheckItemResultInfo itemInfo = getItemByPosition(position);
                holder.setText(R.id.itemNameTv,itemInfo.getName()+"：");
                holder.setText(R.id.valueTv,itemInfo.getValue());
            }
        };
    }


    @Override
    public void initView() {
        super.initView();
        titleTv.setText("检测详情");
        mRefreshLayout.setEnableLoadmore(false);
        mRefreshLayout.setEnableRefresh(false);

    }


    @Override
    public void itemClick(int position) {

    }

    @Override
    public void getDataFromServer() {
        CheckItemInfo checkItemInfo =  getP().getScanResultByID(_id);
        String json = checkItemInfo.getDataJson();
        Type type = new TypeToken<ArrayList<CheckItemResultInfo>>() {
        }.getType();
        ArrayList<CheckItemResultInfo> list = new Gson().fromJson(json, type);
        onSuccess(list);
    }

    @Override
    public void getIntentData() {
        _id = getIntent().getLongExtra("_ID",0);
    }

    @Override
    public BasePresent newP() {
        return new BasePresent();
    }
}
